package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsUserMapper;
import com.qf.mapper.StatMapper;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsUserService;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Cc
 * @version 1.0
 */
@Service
public class DtsUserServiceImpl implements DtsUserService {

    @Autowired
    private  DtsUserMapper userMapper;
    @Autowired
    private StatMapper statMapper;

    @Override
    public int count() {
        QueryWrapper<DtsUser> wapper = new QueryWrapper<>();
        wapper.eq("deleted", false);
        Integer count = userMapper.selectCount(wapper);
        return count;
    }

    @Override
    public List<DayStatis> recentCount(int statisDaysRang) {
        List<DayStatis> list = statMapper.userDayStatistic(statisDaysRang);
        return list;
    }

    @Override
    public IPage<DtsUser> page(Integer page, Integer limit, String sort, String order) {
        return userMapper.selectPage(new Page<>(page, limit),
                new QueryWrapper<DtsUser>()
                        .eq("deleted", false)
                        .orderBy(!StringUtils.isEmpty(sort),"DESC".equalsIgnoreCase(order),sort));
    }
}
